package com.zr.gdms.daoimpl;

import java.nio.charset.MalformedInputException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.zr.gdms.dao.TeacherSelectStudentdao;
import com.zr.gdms.model.Student;
import com.zr.gdms.util.JDBCUtil;
/**
 * 功能逻辑层实现接口
 * 查找功能
 * @author 陈辉
 *
 */
public class TeacherSelectStudentdaoimpl implements TeacherSelectStudentdao {

	@Override
	public List<Student> getTeacherSelStudent(int uid) {
		// TODO Auto-generated method stub
		List<Student> st=new ArrayList<Student>();
		StringBuffer sq1=new StringBuffer();
		sq1.append(" SELECT student.sid,student.sname,student.sage,student.ssex,student.sdepart,student.stel,student.sstate");
		sq1.append(" FROM student");
		sq1.append(" INNER JOIN `user`");
		sq1.append(" ON student.uid=`user`.uid");
		sq1.append(" INNER JOIN teacher");
		sq1.append(" ON teacher.uid=`user`.uid");
		Connection con=JDBCUtil.getConnection();
		try {
			PreparedStatement pst=con.prepareStatement(sq1.toString());
			ResultSet rs=pst.executeQuery();
			while(rs.next()){
				Student ss=new Student();
				ss.setSid(rs.getInt("sid"));
				ss.setSname(rs.getString("sname"));
				ss.setSage(rs.getString("sage"));			
				ss.setSsex(rs.getString("ssex"));
				ss.setSdepart(rs.getString("sdepart"));
				ss.setStel(rs.getString("stel"));			
				ss.setSstate(rs.getString("sstate"));
				st.add(ss);	
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return st;
	}

	

}
